﻿# -*- coding: utf-8 -*-
import core

commandTable = {}
commandStepTable = {}
uncommandTable = {}

def def_op(name, *op, **kwargs):
    commandTable[name] = op
    argc = kwargs.get("argc")
    if argc > 0:
        commandStepTable["{0}{1:02X}".format(name, argc)] = op
    code = [chr(c) for c in op]
    # 같은 명령에서도 스텝수는 다를 수 있기 때문에
    # 스텝수를 제외한 나머지만으로 키를 만든다.
    if 1 < len(code):
        del(code[1])
    code = "".join(code)
    uncommandTable[code] = name

def def_cmp(name, *op):
    def_op("LD"  + name, *op + (0x10,))
    def_op("AND" + name, *op + (0x11,))
    def_op("OR"  + name, *op + (0x12,))

def def_cmd(name, *op, **kwargs):
    def_op(name, *op, **kwargs)
    def_op(name + "P", *op + (0x02,), **kwargs)

# ============================================================================
# 시퀀스 명령
# ============================================================================

# 접점 명령
def_op("LD",    0x00)
def_op("LDI",   0x01)
def_op("LDP",   0x02)
def_op("LDF",   0x03)
def_op("OR",    0x06)
def_op("ORI",   0x07)
def_op("ORP",   0x08)
def_op("ORF",   0x09)
def_op("AND",   0x0C)
def_op("ANI",   0x0D)
def_op("ANDP",  0x0E)
def_op("ANDF",  0x0F)

# 결합 명령
def_op("EGP",   0x10)
def_op("EGF",   0x11)
def_op("MEP",   0x12)
def_op("MEF",   0x13)
def_op("INV",   0x14)
def_op("ORB",   0x18)
def_op("ANB",   0x19)
def_op("MPS",   0x1A)
def_op("MRD",   0x1B)
def_op("MPP",   0x1C)

LD = ("LD", "LDI", "LDP", "LDF")
OR = ("OR", "ORI", "ORP", "ORF")
AND = ("AND", "ANI", "ANDP", "ANDF", "EGP", "EGF", "MEP", "MEF", "INV")
CONTACT = LD + OR + AND + ("ORB", "ANB")
CONNECT = ("MPS", "MRD", "MPP")
CONDITION = CONTACT + CONNECT

# 출력 명령
def_op("OUT",   0x20)
def_op("OUT",   0x21, 0x04) # Timer
def_op("OUTH",  0x22, 0x04) # Timer
def_op("SET",   0x23)
def_op("RST",   0x24)
def_op("PLS",   0x25)
def_op("PLF",   0x26)
def_op("FF",    0x27, 0x02)
def_op("DELTA", 0x28, 0x02)
def_op("DELTAP",0x29, 0x02)

# 시프트 명령
def_op("SFT",   0x2A, 0x02)
def_op("SFTP",  0x2B, 0x02)

# 마스터 컨트롤 명령
def_op("MC",    0x2C, 0x02)
def_op("MCR",   0x30)

# 종료 명령
def_op("FEND",  0x33)
def_op("END",   0x34)

# 기타 명령
def_op("STOP",  0x2D)
# NOP는 코드가 전혀 없는 형태이기 때문에 현재로서는 표현하기가 좀 그렇다.
#def_op("NOP",  None)
def_op("NOPLF", 0x38)
def_op("PAGE",  0x32)
def_op("SUB",   0x3C)

# ============================================================================
# 기본 명령
# ============================================================================

# 비교 연산 명령
def_cmp("=",    0x40, 0x03, 0x00)
def_cmp("<>",   0x40, 0x03, 0x01)
def_cmp(">",    0x40, 0x03, 0x02)
def_cmp(">=",   0x40, 0x03, 0x03)
def_cmp("<",    0x40, 0x03, 0x04)
def_cmp("<=",   0x40, 0x03, 0x05)
def_cmp("D=",   0x40, 0x03, 0x06)
def_cmp("D<>",  0x40, 0x03, 0x07)
def_cmp("D>",   0x40, 0x03, 0x08)
def_cmp("D>=",  0x40, 0x03, 0x09)
def_cmp("D<",   0x40, 0x03, 0x0A)
def_cmp("D<=",  0x40, 0x03, 0x0B)

# 산술 연산 명령
def_cmd("+",    0x49, 0x03, 0x00, argc=2)
def_cmd("+",    0x49, 0x04, 0x01, argc=3)
def_cmd("-",    0x49, 0x03, 0x02, argc=2)
def_cmd("-",    0x49, 0x04, 0x03, argc=3)
def_cmd("D+",   0x49, 0x03, 0x04, argc=2)
def_cmd("D+",   0x49, 0x04, 0x05, argc=3)
def_cmd("D-",   0x49, 0x03, 0x06, argc=2)
def_cmd("D-",   0x49, 0x03, 0x07, argc=3)
def_cmd("*",    0x49, 0x03, 0x08)
def_cmd("/",    0x49, 0x03, 0x0A)
def_cmd("D*",   0x49, 0x03, 0x0C)
def_cmd("D/",   0x49, 0x03, 0x0E)
def_cmd("B+",   0x49, 0x03, 0x10, argc=2)
def_cmd("B+",   0x49, 0x04, 0x11, argc=3)
def_cmd("B-",   0x49, 0x03, 0x12, argc=2)
def_cmd("B-",   0x49, 0x04, 0x13, argc=3)
def_cmd("DB+",  0x49, 0x03, 0x14, argc=2)
def_cmd("DB+",  0x49, 0x04, 0x15, argc=3)
def_cmd("DB-",  0x49, 0x03, 0x16, argc=2)
def_cmd("DB-",  0x49, 0x04, 0x17, argc=3)
def_cmd("B*",   0x49, 0x03, 0x18)
def_cmd("B/",   0x49, 0x04, 0x19)
def_cmd("DB*",  0x49, 0x03, 0x1A)
def_cmd("DB/",  0x49, 0x04, 0x1B)
def_cmd("E+",   0x49, 0x03, 0x1C, argc=2)
def_cmd("E+",   0x49, 0x04, 0x1D, argc=3)
def_cmd("E-",   0x49, 0x03, 0x1E, argc=2)
def_cmd("E-",   0x49, 0x04, 0x1F, argc=3)
def_cmd("E*",   0x49, 0x03, 0x20)
def_cmd("E/",   0x49, 0x04, 0x21)
def_cmd("$+",   0x49, 0x03, 0x22, argc=2)
def_cmd("$+",   0x49, 0x04, 0x23, argc=3)
def_cmd("BK+",  0x49, 0x05, 0x26)
def_cmd("BK-",  0x49, 0x05, 0x27)
def_cmd("INC",  0x4A, 0x02, 0x00)
def_cmd("DINC", 0x4A, 0x02, 0x01)
def_cmd("DEC",  0x4A, 0x02, 0x02)
def_cmd("DDEC", 0x4A, 0x02, 0x03)

# 데이터 변환 명령
def_cmd("BCD",  0x4B, 0x03, 0x00)
def_cmd("DBCD", 0x4B, 0x03, 0x01)
def_cmd("BIN",  0x4B, 0x03, 0x02)
def_cmd("DBIN", 0x4B, 0x03, 0x03)
def_cmd("INT",  0x4B, 0x03, 0x04)
def_cmd("DINT", 0x4B, 0x03, 0x05)
def_cmd("FLT",  0x4B, 0x03, 0x06)
def_cmd("DFLT", 0x4B, 0x03, 0x07)
def_cmd("DBL",  0x4B, 0x03, 0x08)
def_cmd("WORD", 0x4B, 0x03, 0x09)
def_cmd("GRY",  0x4B, 0x03, 0x0A)
def_cmd("DGRY", 0x4B, 0x03, 0x0B)
def_cmd("GBIN", 0x4B, 0x03, 0x0C)
def_cmd("DGBIN",0x4B, 0x03, 0x0D)
def_cmd("NEG",  0x4B, 0x02, 0x0E)
def_cmd("DNEG", 0x4B, 0x02, 0x0F)
def_cmd("ENEG", 0x4B, 0x02, 0x10)
def_cmd("BKBCD",0x4B, 0x04, 0x11)
def_cmd("BKBIN",0x4B, 0x04, 0x12)

# 데이터 전송 명령
def_cmd("MOV",  0x4C, 0x02, 0x00)
def_cmd("DMOV", 0x4C, 0x02, 0x01)
def_cmd("EMOV", 0x4C, 0x03, 0x02)
def_cmd("$MOV", 0x4C, 0x03, 0x03)
def_cmd("CML",  0x4C, 0x03, 0x04)
def_cmd("DCML", 0x4C, 0x03, 0x05)
def_cmd("BMOV", 0x4C, 0x04, 0x06)
def_cmd("FMOV", 0x4C, 0x04, 0x07)
def_cmd("XCH",  0x4C, 0x03, 0x08)
def_cmd("DXCH", 0x4C, 0x03, 0x09)
def_cmd("BXCH", 0x4C, 0x04, 0x0A)
def_cmd("SWAP", 0x4C, 0x03, 0x0B)

# 프로그램 분기 명령
def_op("CJ",    0x4D, 0x02, 0x00)
def_op("SCJ",   0x4D, 0x02, 0x01)
def_op("JMP",   0x68, 0x02, 0x00)
def_op("GOEND", 0x4D, 0x01, 0x06)

# 프로그램 실행 제어 명령
def_op("DI",    0x69, 0x01, 0x00)
def_op("EI",    0x69, 0x01, 0x01)
def_op("IMASK", 0x69, 0x02, 0x02)
def_op("IRET",  0x69, 0x01, 0x03)

# I/O 리플래시 명령
def_cmd("RFS",  0x4E, 0x03, 0x00)

# 기타 편리 명령
def_op("UDCNT1",0x63, 0x04, 0x00)
def_op("UDCNT2",0x63, 0x04, 0x01)
def_op("TTMR",  0x63, 0x03, 0x02)
def_op("STMR",  0x63, 0x04, 0x03)
def_op("ROTC",  0x63, 0x05, 0x04)
def_op("RAMP",  0x63, 0x06, 0x05)
def_op("SPD",   0x63, 0x04, 0x06)
def_op("PLSY",  0x63, 0x04, 0x07)
def_op("PWM",   0x63, 0x04, 0x08)
def_op("MTR",   0x63, 0x05, 0x09)

# ============================================================================
# 응용 명령
# ============================================================================

# 논리 연산 명령
def_cmd("WAND", 0x4F, 0x03, 0x00)
def_cmd("WAND", 0x4F, 0x04, 0x01)
def_cmd("WOR",  0x4F, 0x03, 0x02)
def_cmd("WOR",  0x4F, 0x04, 0x03)
def_cmd("WXOR", 0x4F, 0x03, 0x04)
def_cmd("WXOR", 0x4F, 0x04, 0x05)
def_cmd("WXNR", 0x4F, 0x03, 0x06)
def_cmd("WXNR", 0x4F, 0x04, 0x07)
def_cmd("DAND", 0x4F, 0x03, 0x08)
def_cmd("DAND", 0x4F, 0x04, 0x09)
def_cmd("DOR",  0x4F, 0x03, 0x0A)
def_cmd("DOR",  0x4F, 0x04, 0x0B)
def_cmd("DXOR", 0x4F, 0x03, 0x0C)
def_cmd("DXOR", 0x4F, 0x04, 0x0D)
def_cmd("DXNR", 0x4F, 0x03, 0x0E)
def_cmd("DXNR", 0x4F, 0x04, 0x0F)
def_cmd("BKAND",0x4F, 0x05, 0x10)
def_cmd("BKOR", 0x4F, 0x05, 0x11)
def_cmd("BKXOR",0x4F, 0x05, 0x12)
def_cmd("BKXNR",0x4F, 0x05, 0x13)

# 로테이션 명령
def_cmd("ROR",  0x50, 0x03, 0x00)
def_cmd("RCR",  0x50, 0x03, 0x01)
def_cmd("ROL",  0x50, 0x03, 0x02)
def_cmd("RCL",  0x50, 0x03, 0x03)
def_cmd("DROR", 0x50, 0x03, 0x04)
def_cmd("DRCR", 0x50, 0x03, 0x05)
def_cmd("DROL", 0x50, 0x03, 0x06)
def_cmd("DRCL", 0x50, 0x03, 0x07)

# 시프트 명령
def_cmd("SFR",  0x51, 0x03, 0x00)
def_cmd("SFL",  0x51, 0x03, 0x01)
def_cmd("BSFR", 0x51, 0x03, 0x02)
def_cmd("BSFL", 0x51, 0x03, 0x03)
def_cmd("DSFR", 0x51, 0x03, 0x04)
def_cmd("DSFL", 0x51, 0x03, 0x05)

# 비트 처리 명령
def_cmd("BSET", 0x52, 0x03, 0x00)
def_cmd("BRST", 0x52, 0x03, 0x01)
def_cmd("TEST", 0x52, 0x04, 0x02)
def_cmd("DTEST",0x52, 0x04, 0x03)
def_cmd("BKRST",0x52, 0x03, 0x04)

# 데이터 처리 명령
def_cmd("SER",  0x53, 0x05, 0x00)
def_cmd("DSER", 0x53, 0x05, 0x01)
def_cmd("SUM",  0x53, 0x03, 0x02)
def_cmd("DSUM", 0x53, 0x03, 0x03)
def_cmd("DECO", 0x53, 0x04, 0x04)
def_cmd("ENCO", 0x53, 0x04, 0x05)
def_cmd("SEG",  0x53, 0x03, 0x06)
def_cmd("DIS",  0x53, 0x04, 0x07)
def_cmd("UNI",  0x53, 0x04, 0x08)
def_cmd("NDIS", 0x53, 0x04, 0x09)
def_cmd("NUNI", 0x53, 0x04, 0x0A)
def_cmd("WTOB", 0x53, 0x04, 0x0B)
def_cmd("BTOW", 0x53, 0x04, 0x0C)
def_cmd("MAX",  0x53, 0x04, 0x0D)
def_cmd("DMAX", 0x53, 0x04, 0x0E)
def_cmd("MIN",  0x53, 0x04, 0x0F)
def_cmd("DMIN", 0x53, 0x04, 0x10)
def_cmd("SORT", 0x53, 0x06, 0x11)
def_cmd("DSORT",0x53, 0x06, 0x12)
def_cmd("WSUM", 0x53, 0x04, 0x13)
def_cmd("DWSUM",0x53, 0x04, 0x14)

# 구조화 명령
def_cmd("BREAK",  0x54, 0x04, 0x00)
def_cmd("CALL",   0x54, 0x02, 0x01)
def_cmd("CALL",   0x54, 0x03, 0x02)
def_cmd("CALL",   0x54, 0x04, 0x03)
def_cmd("CALL",   0x54, 0x05, 0x04)
def_cmd("CALL",   0x54, 0x06, 0x05)
def_cmd("CALL",   0x54, 0x07, 0x06)
def_cmd("FCALL",  0x54, 0x02, 0x07)
def_cmd("FCALL",  0x54, 0x03, 0x08)
def_cmd("FCALL",  0x54, 0x04, 0x09)
def_cmd("FCALL",  0x54, 0x05, 0x0A)
def_cmd("FCALL",  0x54, 0x06, 0x0B)
def_cmd("FCALL",  0x54, 0x07, 0x0C)
def_cmd("ECALL",  0x54, 0x03, 0x0D)
def_cmd("ECALL",  0x54, 0x04, 0x0E)
def_cmd("ECALL",  0x54, 0x05, 0x0F)
def_cmd("ECALL",  0x54, 0x06, 0x10)
def_cmd("ECALL",  0x54, 0x07, 0x11)
def_cmd("ECALL",  0x54, 0x08, 0x12)
def_cmd("EFCALL", 0x54, 0x03, 0x13)
def_cmd("EFCALL", 0x54, 0x04, 0x14)
def_cmd("EFCALL", 0x54, 0x05, 0x15)
def_cmd("EFCALL", 0x54, 0x06, 0x16)
def_cmd("EFCALL", 0x54, 0x07, 0x17)
def_cmd("EFCALL", 0x54, 0x08, 0x18)
def_op("IXSET",   0x54, 0x03, 0x19)

def_op("FOR",   0x6A, 0x02, 0x00)
def_op("NEXT",  0x6A, 0x01, 0x01)
def_op("RET",   0x6A, 0x01, 0x02)
def_op("IX",    0x6A, 0x02, 0x03)
def_op("IXEND", 0x6A, 0x01, 0x04)
def_op("IXDEV", 0x6A, 0x01, 0x05)
def_op("COM",   0x6A, 0x01, 0x06)

# 테이블 조작 명령
def_cmd("FIFW", 0x55, 0x03, 0x00)
def_cmd("FIFR", 0x55, 0x03, 0x01)
def_cmd("FPOP", 0x55, 0x03, 0x02)
def_cmd("FINS", 0x55, 0x04, 0x03)
def_cmd("FDEL", 0x55, 0x04, 0x04)

# 버퍼 메모리 엑세스 명령
def_cmd("FROM", 0x56, 0x05, 0x00)
def_cmd("DFRO", 0x56, 0x05, 0x01)
def_cmd("TO",   0x56, 0x05, 0x02)
def_cmd("DTO",  0x56, 0x05, 0x03)

# 표시 명령
def_op("PR",    0x57, 0x03, 0x00)
def_op("PRC",   0x57, 0x03, 0x01)
#def_op("LED",   0x57, 0x02, 0x02)
#def_op("LEDC",  0x57, 0x02, 0x03)
def_op("LEDR",  0x57, 0x01, 0x04)

# 디버그, 고장 진단 명령
def_op("CHKST",  0x58, 0x01, 0x00)
def_op("CHK",    0x58, 0x01, 0x01)
def_op("CHKCIR", 0x58, 0x01, 0x02)
def_op("CHKEND", 0x58, 0x01, 0x03)

# 문자열 처리 명령
def_cmd("BINDA",  0x59, 0x03, 0x00)
def_cmd("DBINDA", 0x59, 0x03, 0x01)
def_cmd("BINHA",  0x59, 0x03, 0x02)
def_cmd("DBINHA", 0x59, 0x03, 0x03)
def_cmd("BCDDA",  0x59, 0x03, 0x04)
def_cmd("DBCDDA", 0x59, 0x03, 0x05)
def_cmd("DABIN",  0x59, 0x03, 0x06)
def_cmd("DDABIN", 0x59, 0x03, 0x07)
def_cmd("HABIN",  0x59, 0x03, 0x08)
def_cmd("DHABIN", 0x59, 0x03, 0x09)
def_cmd("DABCD",  0x59, 0x03, 0x0A)
def_cmd("DDABCD", 0x59, 0x03, 0x0B)
def_cmd("COMRD",  0x59, 0x03, 0x0C)
def_cmd("LEN",    0x59, 0x03, 0x0D)
def_cmd("STR",    0x59, 0x04, 0x0E)
def_cmd("DSTR",   0x59, 0x04, 0x0F)
def_cmd("VAL",    0x59, 0x04, 0x10)
def_cmd("DVAL",   0x59, 0x04, 0x11)
def_cmd("ESTR",   0x59, 0x04, 0x12)
def_cmd("EVAL",   0x59, 0x03, 0x13)
def_cmd("ASC",    0x59, 0x04, 0x14)
def_cmd("HEX",    0x59, 0x04, 0x15)
def_cmd("LEFT",   0x59, 0x04, 0x16)
def_cmd("RIGHT",  0x59, 0x04, 0x17)
def_cmd("MIDR",   0x59, 0x04, 0x18)
def_cmd("MIDW",   0x59, 0x04, 0x19)
def_cmd("INSTR",  0x59, 0x05, 0x1A)
def_cmd("EMOD",   0x59, 0x04, 0x1B)
def_cmd("EREXP",  0x59, 0x04, 0x1C)

# 특수 함수 명령
def_cmd("SIN",    0x5A, 0x03, 0x00)
def_cmd("COS",    0x5A, 0x03, 0x01)
def_cmd("TAN",    0x5A, 0x03, 0x02)
def_cmd("ASIN",   0x5A, 0x03, 0x03)
def_cmd("ACOS",   0x5A, 0x03, 0x04)
def_cmd("ATAN",   0x5A, 0x03, 0x05)
def_cmd("RAD",    0x5A, 0x03, 0x06)
def_cmd("DEG",    0x5A, 0x03, 0x07)
def_cmd("SQR",    0x5A, 0x03, 0x08)
def_cmd("EXP",    0x5A, 0x03, 0x09)
def_cmd("LOG",    0x5A, 0x03, 0x0A)
def_cmd("RND",    0x5A, 0x03, 0x0B)
def_cmd("SRND",   0x5A, 0x03, 0x0C)
def_cmd("BSQR",   0x5A, 0x03, 0x0D)
def_cmd("BDSQR",  0x5A, 0x04, 0x0E)
def_cmd("BSIN",   0x5A, 0x04, 0x0F)
def_cmd("BCOS",   0x5A, 0x04, 0x10)
def_cmd("BTAN",   0x5A, 0x04, 0x11)
def_cmd("BASIN",  0x5A, 0x04, 0x12)
def_cmd("BACOS",  0x5A, 0x03, 0x13)
def_cmd("BATAN",  0x5A, 0x04, 0x14)

# 데이터 제어 명령
def_cmd("LIMIT",  0x5B, 0x05, 0x00)
def_cmd("DLIMIT", 0x5B, 0x05, 0x01)
def_cmd("BAND",   0x5B, 0x05, 0x02)
def_cmd("DBAND",  0x5B, 0x05, 0x03)
def_cmd("ZONE",   0x5B, 0x05, 0x04)
def_cmd("DZONE",  0x5B, 0x05, 0x05)

# 파일 레지스터 전환 명령
def_cmd("RSET",   0x5C, 0x02, 0x00)
def_cmd("QDRSET", 0x5C, 0x02, 0x01)
def_cmd("QCDSET", 0x5C, 0x02, 0x02)

# 시계용 명령
def_cmd("DATERD", 0x5D, 0x02, 0x00)
def_cmd("DATEWR", 0x5D, 0x02, 0x01)
def_cmd("DATE+",  0x5D, 0x04, 0x02)
def_cmd("DATE-",  0x5D, 0x04, 0x03)
def_cmd("SECOND", 0x5D, 0x03, 0x04)
def_cmd("HOUR",   0x5D, 0x03, 0x05)

# 주변 기기용 명령
def_op("MSG",     0x5F, 0x02, 0x00)
def_op("PKEY",    0x5F, 0x02, 0x01)

# 프로그램 명령
def_cmd("PSTOP",  0x60, 0x02, 0x00)
def_cmd("POFF",   0x60, 0x02, 0x01)
def_cmd("PSCAN",  0x60, 0x02, 0x02)
def_cmd("PLOW",   0x60, 0x02, 0x03)

# 기타 명령
def_cmd("WDT",    0x61, 0x01, 0x00)
def_cmd("DUTY",   0x61, 0x04, 0x01)
def_cmd("ZRRDB",  0x61, 0x03, 0x02)
def_cmd("ZRWRB",  0x61, 0x03, 0x03)
def_cmd("ADRSET", 0x61, 0x03, 0x04)
def_op("KEY",     0x61, 0x05, 0x05)
def_cmd("ZPUSH",  0x61, 0x02, 0x0A)
def_cmd("ZPOP",   0x61, 0x02, 0x0B)
#def_cmd("EROMWR", 0x61, 0x05, 0x0C)

# 데이터 링크용 명령
# 모두 시스템 확장 명령이다

# QCPU용 명령
def_cmd("UNIRD",   0x65, 0x04, 0x00)
def_op("TRACE",    0x65, 0x01, 0x01)
def_op("TRACER",   0x65, 0x01, 0x02)
def_op("PLOADP",   0x65, 0x03, 0x05, 0x02)
def_op("PUNLOADP", 0x65, 0x03, 0x06, 0x02)
def_op("PSWAPP",   0x65, 0x04, 0x07, 0x02)
def_cmd("RBMOV",   0x65, 0x04, 0x10)
# 나머지는 시스템 확장 명령이다

# 이중화 시스템용 명령(Q4ARCPU)
# 모두 시스템 확장 명령이다

# 시스템 확장 명령
def_op("S.",  0x70, 0x02, 0x00, 0x0A)
def_op("SP.", 0x70, 0x02, 0x00, 0x02)
def_op("Z.",  0x71, 0x02, 0x00, 0x0A)
def_op("ZP.", 0x71, 0x02, 0x00, 0x02)
def_op("G.",  0x72, 0x02, 0x00, 0x0A)
def_op("GP.", 0x72, 0x02, 0x00, 0x02)
def_op("J.",  0x73, 0x02, 0x00, 0x0A)
def_op("JP.", 0x73, 0x02, 0x00, 0x02)

# SFC
def_op("STEPSYNC0", 0x42, 0x02, 0x00)
def_op("STEPSYNC1", 0x42, 0x01, 0x01)
def_op("JUMPTO", 0x62, 0x02, 0x00)

def_op("SFC",          0x6C, 0x01, 0x00)
def_op("END_SFC",      0x6C, 0x01, 0x01)
def_op("BLOCK",        0x6C, 0x01, 0x02)
def_op("END_BLOCK",    0x6C, 0x01, 0x03)
def_op("TRANS",        0x6C, 0x02, 0x04)
def_op("SELECT",       0x6C, 0x02, 0x05)
def_op("PARALLEL",     0x6C, 0x02, 0x06)
def_op("END_PARALLEL", 0x6C, 0x02, 0x07)
def_op("END_STEP",     0x6C, 0x01, 0x0A)
def_op("END_SELECT",   0x6C, 0x01, 0x0B)
def_op("STEP_--",      0x6C, 0x02, 0x0F)
def_op("STEP_DUMMY",   0x6C, 0x02, 0x10)
def_op("STEP_SC",      0x6C, 0x02, 0x11)
def_op("STEP_SE",      0x6C, 0x02, 0x12)
def_op("STEP_ST",      0x6C, 0x02, 0x13)
def_op("STEP_R",       0x6C, 0x02, 0x14)
def_op("CALL_BLOCK",   0x6C, 0x04, 0x15)
def_op("CALL_BLOCK-S", 0x6C, 0x04, 0x16)
def_op("STEP_INIT",    0x6C, 0x02, 0x17)
def_op("TRANS_1D",     0x6C, 0x02, 0x1d)
def_op("SELECT_1E",    0x6C, 0x02, 0x1e)


NO_COND_CMDS = ("END", "FEND", "FOR", "NEXT")

del def_cmd
del def_cmp
del def_op

def getname(s):
    key = s[0] + s[2:]
    steps = 1
    if len(s) > 1:
        steps = ord(s[1])
    try:
        return uncommandTable[key], steps
    except KeyError:
        return core.dump(key), steps

def getcode(s, argc=0):
    if argc > 0:
        ss = "{0}{1:02X}".format(s, argc)
        if ss in commandStepTable:
            return commandStepTable[ss]
    return commandTable[s]
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

